package com.toune.movie.mvp.adapter;

import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.toune.movie.R;
import com.toune.movie.mvp.activity.VarietyDetailActivity;
import com.toune.movie.vo.VarietyVo;

import java.util.List;

/**
 * Created by mikeafc on 15/11/26.
 */
public class UltraPagerAdapter extends PagerAdapter {
    private boolean isMultiScr;
    List<VarietyVo> varietyVoList;

    public UltraPagerAdapter(List<VarietyVo> varietyVoList, boolean isMultiScr) {
        this.isMultiScr = isMultiScr;
        this.varietyVoList = varietyVoList;
    }

    @Override
    public int getCount() {
        return varietyVoList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(final ViewGroup container, final int position) {
        LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(container.getContext()).inflate(R.layout.item_ultra, null);
        //new LinearLayout(container.getContext());
        TextView textView = (TextView) linearLayout.findViewById(R.id.name_tv);
        textView.setText(varietyVoList.get(position).getTitle());
        ImageView iconIv = linearLayout.findViewById(R.id.icon_iv);
        Glide.with(container.getContext()).load(varietyVoList.get(position).getImagSrc()).into(iconIv);
//        linearLayout.setId(R.id.item_id);
//        switch (position) {
//            case 0:
//                linearLayout.setBackgroundColor(Color.parseColor("#2196F3"));
//                break;
//            case 1:
//                linearLayout.setBackgroundColor(Color.parseColor("#673AB7"));
//                break;
//            case 2:
//                linearLayout.setBackgroundColor(Color.parseColor("#009688"));
//                break;
//            case 3:
//                linearLayout.setBackgroundColor(Color.parseColor("#607D8B"));
//                break;
//            case 4:
//                linearLayout.setBackgroundColor(Color.parseColor("#F44336"));
//                break;
//        }
        linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(container.getContext(), VarietyDetailActivity.class);
                intent.putExtra("url", varietyVoList.get(position).getDetailUrl());
                intent.putExtra("title", varietyVoList.get(position).getTitle());
                container.getContext().startActivity(intent);
            }
        });
        container.addView(linearLayout);
//        linearLayout.getLayoutParams().width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, container.getContext().getResources().getDisplayMetrics());
//        linearLayout.getLayoutParams().height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 400, container.getContext().getResources().getDisplayMetrics());
        return linearLayout;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        LinearLayout view = (LinearLayout) object;
        container.removeView(view);
    }
}